package sim.ring.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;

import sim.ring.gui.RingingSimApp;
import sim.ring.gui.RingingSimManager;
import sim.ring.gui.treedata.MethodTreeContentProvider;

public class AddNewCategoryAction extends Action {
	
	RingingSimApp r;
	
	private static String _DIALOGTITLE, _DIALOGPROMPT;
	
	public AddNewCategoryAction(RingingSimApp parent) {
		r = parent;
		setText(r.getLocalisedData("newCategoryAction", "New &category"));
		setToolTipText(r.getLocalisedData("newCategoryActionTooltip", "Create a new category"));
		setImageDescriptor(RingingSimManager.getIMGReg().getDescriptor("newCategory"));
		_DIALOGPROMPT = r.getLocalisedData("newCategoryDialogPrompt", "Specify category name");
		_DIALOGTITLE = r.getLocalisedData("newCategoryDialogTitle", "Create a new category");
	}
	
	@Override
	public void run() {
		InputDialog dlg = new InputDialog(
				Display.getCurrent().getActiveShell(),
				_DIALOGTITLE, _DIALOGPROMPT,
				"", null);
		if (dlg.open() == Window.OK) {
			((MethodTreeContentProvider)r.getTV().getContentProvider()).addNewCategory(dlg.getValue());
		}
	}

}
